﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class SystemManage_OperationLog : PageBase
{
    int count = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            DateTime dtime = DateTime.Now;
            this.tbStartTime.Value = DateTime.Parse(dtime.Year.ToString() + "-" + dtime.Month + "-01 00:00:00").ToString();
            this.tbEndTime.Value = dtime.ToString();
            this.lbUserName.Text = _User.RealityName;
            ViewState["Op"] = "0";
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestCompetences = Competences.BuildCompetencesList(Competences.Administrator);
        RequestLoginPage = "SystemManage/OperationLog.aspx";

        base.OnInit(e);
    }

    #endregion

    private void BindData()
    {
        DataTable dt = null;
        DataSet ds = null;

        if (ViewState["Op"].ToString().Equals("0"))
        {
            DateTime dTime = ShoveEL._Convert.StrToDateTime(this.tbStartTime.Value.ToString(), "2008-4-1");

            ds = DAL.Procedures.P_OpLogList.Open(dTime, ShoveEL._Convert.StrToDateTime(this.tbEndTime.Value.ToString(), "2008-4-1"));
        }
        else
        {
            User tu = new User();
            tu.Name = this.TextBox1.Text.Trim();
            string ret = "";
            int result = tu.GetUserInfoByName(ref ret);

            if (result != 0)
            {
                ShoveEL._Web.JavaScript.Alert(this, "此会员不存在");

                this.TextBox1.Text = string.Empty;
            }

            ds = DAL.Procedures.P_OpLogUserIDList.Open(tu.ID);
        }

        if (ds == null)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        if (ds.Tables.Count == 0)
        {
            PublicFunction.GoError(ErrorNumber.NoData, "暂无数据", this.GetType().BaseType.FullName);

            return;
        }

        dt = ds.Tables[0];

        this.g.DataSource = dt.DefaultView;
        this.g.DataBind();

        gPager.Visible = (ds.Tables[0].Rows.Count > 0);
    }

    protected void g_ItemDataBound(object sender, DataGridItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            count++;
            if (count >= 10)
            {
                e.Item.Cells[0].Text = "0" + count;
            }
            else
            {
                e.Item.Cells[0].Text = "00" + count;
            }
        }
    }
    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        BindData();
    }
    protected void gPager_SortBefore(object source, DataGridSortCommandEventArgs e)
    {
        BindData();
    }

    protected void ibUser_Click(object sender, ImageClickEventArgs e)
    {
        ViewState["Op"] = "1";
        BindData();
    }

    protected void ibDate_Click(object sender, ImageClickEventArgs e)
    {
        ViewState["Op"] = "0";
        BindData();
    }
}